package controller.gui.menubar;

import gui.MapEditorFrame;

import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JMenuItem;

import map.AbstractMap;

import controller.BackupMapUser;
import controller.Controller;
import controller.MenuBarController;
import controller.NullStaticObjectException;
import controller.MapElementToAddConveyor;

/**rappresenta il Controller che ascolta i lpulsante "exit" nel menu delll'editor
 * 
 * @author koldar
 * @version 1.1
 */
public final class ExitMapController extends MenuBarController implements WindowListener,BackupMapUser,MapElementToAddConveyor{
	
	public ExitMapController(MapEditorFrame _frame,JMenuItem towire){
		super(_frame,towire);
		this.frame.addWindowListener(this);
	}
	
	@Override
	public void wizardInizializer(ActionEvent arg0)throws NullStaticObjectException {
		this.windowClosing(null);
		this.frame.dispose();
	}

	@Override
	public void windowOpened(WindowEvent e) {
	}

	@Override
	public void windowClosing(WindowEvent e) {
		if (this.currentmap!=null){
			this.currentmap.terminate();
			this.currentmap=null;
		}
		if (this.backupmap.getValue()!=null){
			this.backupmap.getValue().terminate();
			this.backupmap.setValue(null);
		}
	}

	@Override
	public void windowClosed(WindowEvent e) {
	}

	@Override
	public void windowIconified(WindowEvent e) {
	}

	@Override
	public void windowDeiconified(WindowEvent e) {
	}

	@Override
	public void windowActivated(WindowEvent e) {
	}

	@Override
	public void windowDeactivated(WindowEvent e) {
	}

	
}
